Page({

  data: {
    ShareNickName:"",
    ShareId: 0,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var ShareId = options.id
    var ShareNickName = options.ShareNickName;
  
    if (ShareNickName != null || typeof ShareNickName != "undefined"){
          console.log("分享人名称为："+ShareNickName+"   "+ShareId);
          this.setData({
            ShareNickName: ShareNickName,
            ShareId: ShareId
          })
       }
       
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },

  authorization: function(){
    var ShareNickName = this.data.ShareNickName
  
    var ShareId = this.data.ShareId;
    var exist=wx.getStorageSync("scope")
        if (exist) {
            wx.reLaunch({
              url: '/pages/canvas/canvas',
              success: function (res) {
              }, fail: function (res) {
                console.log(JSON.stringify(res))
              }
            })
          }else{
      wx.getUserInfo({
        success: function (res) {
          var that = this
          var userInfo = res.userInfo
          var nickName = userInfo.nickName
          var avatarUrl = userInfo.avatarUrl
          var gender = userInfo.gender //性别 0：未知、1：男、2：                 女
          var province = userInfo.province
          var city = userInfo.city
          var country = userInfo.country
          wx.setStorageSync("scope", res.userInfo);

          
          //页面刷新
       
          var token = wx.getStorageSync("token");
          wx.request({
            method: "post",
            url: getApp().globalData.url+'/app/register',
            data: { token: token, 
            userInfo: JSON.stringify(userInfo),
             ShareNickName: ShareNickName,
             ShareId: ShareId          
             }, // 设置请求的 参数
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            success: function (res) {
              // wx.hideLoading();
              wx.reLaunch({
                url: '/pages/canvas/canvas',
                success: function (res) {
                }, fail: function (res) {
                  console.log(JSON.stringify(res))
                }
              })
            }, fail: function (e) {
              console.log("请求失败？")
            }
          })
        
        
      
        }, fail: function (e) {
          console.log("授权错误信息:" + JSON.stringify(e))
        }
      })
          }
    
  }
          
})